﻿<Page
    x:Name="PageRoot"
    x:Class="MultimediaExample.MultimediaPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MultimediaExample"
    xmlns:common="using:MultimediaExample.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DataContext="{d:DesignInstance Type=local:MultimediaViewModel}">

    <Page.Resources>
        <common:EnumTextValueConverter x:Key="EnumTextValueConverter"/>
        <common:DurationDisplayConverter x:Key="DurationDisplayConverter"/>
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.ChildrenTransitions>
            <TransitionCollection>
                <EntranceThemeTransition/>
            </TransitionCollection>
        </Grid.ChildrenTransitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Grid Grid.Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Grid.Resources>
                <Style TargetType="TextBlock" BasedOn="{StaticResource BodyTextBlockStyle}">
                    <Setter Property="Margin" Value="3,0,5,10"/>
                    <Setter Property="VerticalAlignment" Value="Center"/>
                </Style>
                <Style TargetType="TextBlock" BasedOn="{StaticResource BodyTextBlockStyle}" x:Key="BlockHeaderTextBlockStyle">
                    <Setter Property="Margin" Value="3,0,5,10"/>
                    <Setter Property="FontWeight" Value="Bold"></Setter>
                </Style>
                <Style TargetType="Border" x:Key="BlockBorderStyle">
                    <Setter Property="BorderThickness" Value="{StaticResource FlyoutBorderThemeThickness}"/>
                    <Setter Property="BorderBrush" Value="{StaticResource FlyoutBorderThemeBrush}"/>
                    <Setter Property="Padding" Value="5"/>
                    <Setter Property="Margin" Value="5"/>
                </Style>
                <Style TargetType="Button" x:Key="BlockButtonStyle">
                    <Setter Property="HorizontalAlignment" Value="Stretch"/>
                </Style>
            </Grid.Resources>
            <Grid Grid.Column="0" Width="320">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid.Resources>
                    <Style TargetType="Border" BasedOn="{StaticResource BlockBorderStyle}"/>
                    <Style TargetType="Button" BasedOn="{StaticResource BlockButtonStyle}"/>
                </Grid.Resources>
                <Border Grid.Row="0">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <TextBlock Grid.Row="0" Text="Playback Files" Style="{StaticResource BlockHeaderTextBlockStyle}"/>
                        <ListView Grid.Row="1" ItemsSource="{Binding PlaybackFiles}" SelectedItem="{Binding CurrentPlaybackFile, Mode=TwoWay}" DisplayMemberPath="PlaybackFile.Name"/>
                        <Grid Grid.Row="2">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Button Grid.Column="0" Content="Remove" Command="{Binding RemoveSelectedVideoCommand}"/>
                            <Button Grid.Column="1" Content="Add Marker" Click="HandleAddMarkerClicked">
                                <FlyoutBase.AttachedFlyout>
                                    <Flyout >
                                        <Grid Width="400" d:DataContext="{d:DesignInstance Type=local:DesignFileMarkerViewModel}">
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="Auto"/>
                                                <RowDefinition Height="Auto"/>
                                            </Grid.RowDefinitions>
                                            <Grid.Resources>
                                                <Style TargetType="Button">
                                                    <Setter Property="Margin" Value="5"/>
                                                </Style>
                                            </Grid.Resources>
                                            <local:FileMarkerControl Grid.Row="0"/>
                                            <Button Grid.Row="1" Content="Add" Command="{Binding MultimediaViewModel.AddMarkerCommand}" CommandParameter="{Binding FileMarker}" HorizontalAlignment="Stretch"/>
                                        </Grid>
                                    </Flyout>
                                </FlyoutBase.AttachedFlyout>
                            </Button> 
                        </Grid>
                    </Grid>
                </Border>
                <Border Grid.Row="1">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <TextBlock Grid.Row="0" Text="Markers" Style="{StaticResource BlockHeaderTextBlockStyle}"/>
                        <ListView Grid.Row="1" ItemsSource="{Binding CurrentPlaybackFile.FileMarkers}" SelectedItem="{Binding CurrentFileMarker, Mode=TwoWay}" DisplayMemberPath="Name"/>
                        <Grid Grid.Row="2">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Button Grid.Column="0" Content="Remove" Command="{Binding RemoveSelectedMarkerCommand}"/>
                            <Button Grid.Column="1" Content="Update" Click="HandleUpdateMarkerClicked">
                                <FlyoutBase.AttachedFlyout>
                                    <Flyout>
                                        <Grid Width="400" d:DataContext="{d:DesignInstance Type=local:DesignFileMarkerViewModel}">
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="Auto"/>
                                            </Grid.RowDefinitions>
                                            <Grid.Resources>
                                                <Style TargetType="Button">
                                                    <Setter Property="Margin" Value="5"/>
                                                </Style>
                                            </Grid.Resources>
                                            <local:FileMarkerControl Grid.Row="0"/>
                                        </Grid>
                                    </Flyout>
                                </FlyoutBase.AttachedFlyout>
                            </Button>
                        </Grid>
                    </Grid>
                </Border>
            </Grid>
            <Grid Grid.Column="1">
                <Border Style="{StaticResource BlockBorderStyle}">
                    <MediaElement x:Name="PlaybackWindow" 
                                  PosterSource="Assets/SplashScreen.png"
                                  AreTransportControlsEnabled="True" 
                                  IsFullWindow="False"
                                  AutoPlay="True"
                                  IsLooping="False"
                                  />
                </Border>
            </Grid>
            <Grid Grid.Column="2" Width="320">
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Grid.Resources>
                    <Style TargetType="Border" BasedOn="{StaticResource BlockBorderStyle}"/>
                    <Style TargetType="Button" BasedOn="{StaticResource BlockButtonStyle}"/>
                </Grid.Resources>
                <Border Grid.Row="0">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Grid Grid.Row="0">
                            <TextBlock Grid.Row="0" Grid.Column="0" Text="Playback Behavior" Style="{StaticResource BlockHeaderTextBlockStyle}"/>
                        </Grid>
                        <Grid Grid.Row="1">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>

                            <TextBlock Grid.Row="0" Grid.Column="0" Text="Show Controls:" Margin="3,0,4.5,10" VerticalAlignment="Bottom"/>
                            <CheckBox Grid.Row="0" Grid.Column="1" IsChecked="{Binding AreTransportControlsEnabled, ElementName=PlaybackWindow, Mode=TwoWay}" />
                            <TextBlock Grid.Row="0" Grid.Column="2" Text="Full Screen:"/>
                            <CheckBox Grid.Row="0" Grid.Column="3" IsChecked="{Binding IsFullWindow, ElementName=PlaybackWindow, Mode=TwoWay}" />

                            <Grid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="5">
                               <Grid.ColumnDefinitions>
                                   <ColumnDefinition Width="*"/>
                                   <ColumnDefinition Width="*"/>
                                   <ColumnDefinition Width="*"/>
                               </Grid.ColumnDefinitions>
                                <Button Grid.Column="0" Content="Play" Command="{Binding PlayCommand}"/>
                                <Button Grid.Column="1" Content="Pause" Command="{Binding PauseCommand}"/>
                                <Button Grid.Column="2" Content="Stop" Command="{Binding StopCommand}"/>
                            </Grid>
                        
                            <Grid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="5">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Button Grid.Column="0" Content="Back 5 sec" Command="{Binding Minus5Command}"/>
                                <StackPanel Grid.Column="1" Orientation="Horizontal">
                                    <TextBlock Text="Slo-Mo:"/>
                                    <CheckBox IsChecked="{Binding IsSlowMotionPlayback, Mode=TwoWay}"/>
                                </StackPanel>
                                <Button Grid.Column="2" Content="Fwd 5 sec" Command="{Binding Plus5Command}"/>
                            </Grid>
                            <TextBlock Grid.Row="3" Grid.Column="0" Text="AutoPlay:"/>
                            <CheckBox Grid.Row="3" Grid.Column="1" IsChecked="{Binding AutoPlay, ElementName=PlaybackWindow, Mode=TwoWay}" />
                            <TextBlock Grid.Row="3" Grid.Column="2" Text="Loop Current:"/>
                            <CheckBox Grid.Row="3" Grid.Column="3" IsChecked="{Binding IsLooping, ElementName=PlaybackWindow, Mode=TwoWay}" />

                            <Grid Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="5">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <TextBlock Grid.Column="0" Text="State:"/>
                                <TextBlock Grid.Column="1" Text="{Binding CurrentState, ElementName=PlaybackWindow, Mode=OneWay, Converter={StaticResource EnumTextValueConverter}}"/>
                            </Grid>
                        </Grid>
                        <Grid Grid.Row="2">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <Slider Grid.Row="0" Grid.Column="0" Header="Volume:" 
                                    Margin="5,0"
                                    Minimum="0" Maximum="1" 
                                    SmallChange="0.01" LargeChange="0.1" StepFrequency="0.1" 
                                    Value="{Binding Volume, ElementName=PlaybackWindow, Mode=TwoWay}"/>
                            <Grid Grid.Row="0" Grid.Column="1" Margin="10,0">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <TextBlock Grid.Row="0" Text="Muted:"/>
                                <CheckBox Grid.Row="1" IsChecked="{Binding IsMuted, ElementName=PlaybackWindow, Mode=TwoWay}" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,12"/>
                            </Grid>
                            <Slider Grid.Row="1" Grid.Column="0" Header="Balance:" Minimum="-1" Maximum="1" SmallChange="0.02" StepFrequency="0.2" LargeChange="0.2" Value="{Binding Balance, ElementName=PlaybackWindow, Mode=TwoWay}" Margin="5,0"/>
                        </Grid>
                    </Grid>
                </Border>
                <Border Grid.Row="1">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <TextBlock Grid.Row="0" Text="Information" Style="{StaticResource BlockHeaderTextBlockStyle}"/>
                        <TextBlock Grid.Row="1" Grid.Column="0" Text="Duration:"/>
                        <TextBlock Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="4" Text="{Binding NaturalDuration, ElementName=PlaybackWindow, Converter={StaticResource DurationDisplayConverter}}"/>
                        <TextBlock Grid.Row="2" Grid.Column="0" Text="Aspect Ratio:"/>
                        <StackPanel Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="4" Orientation="Horizontal">
                            <TextBlock Text="{Binding AspectRatioWidth, ElementName=PlaybackWindow, Mode=OneWay}"/>
                            <TextBlock Text="x"/>
                            <TextBlock Text="{Binding AspectRatioHeight, ElementName=PlaybackWindow, Mode=OneWay}"/>
                        </StackPanel>
                        <TextBlock Grid.Row="3" Grid.Column="0" Text="Width:"/>
                        <TextBlock Grid.Row="3" Grid.Column="1" Text="{Binding NaturalVideoWidth, ElementName=PlaybackWindow, Mode=OneWay}"/>
                        <TextBlock Grid.Row="3" Grid.Column="3" Text="Height:"/>
                        <TextBlock Grid.Row="3" Grid.Column="4" Text="{Binding NaturalVideoHeight, ElementName=PlaybackWindow, Mode=OneWay}"/>

                        <TextBlock Grid.Row="4" Grid.Column="0" Text="Audio Only:"/>
                        <CheckBox Grid.Row="4" Grid.Column="1" IsChecked="{Binding IsAudioOnly, ElementName=PlaybackWindow, Mode=OneWay}" IsEnabled="False"/>
                        <TextBlock Grid.Row="5" Grid.Column="0" Text="Category:"/>
                        <TextBlock Grid.Row="5" Grid.Column="1" Text="{Binding AudioCategory, ElementName=PlaybackWindow, Mode=OneWay, Converter={StaticResource EnumTextValueConverter}}"/>
                        <TextBlock Grid.Row="5" Grid.Column="3" Text="Device Type:"/>
                        <TextBlock Grid.Row="5" Grid.Column="4" Text="{Binding AudioDeviceType, ElementName=PlaybackWindow, Mode=OneWay, Converter={StaticResource EnumTextValueConverter}}"/>
                        <TextBlock Grid.Row="6" Grid.Column="0" Text="Streams:"/>
                        <TextBlock Grid.Row="6" Grid.Column="1" Text="{Binding AudioStreamCount, ElementName=PlaybackWindow, Mode=OneWay}"/>
                        <TextBlock Grid.Row="6" Grid.Column="3" Text="Stream Idx:"/>
                        <TextBlock Grid.Row="6" Grid.Column="4" Text="{Binding AudioStreamIndex, ElementName=PlaybackWindow, Mode=OneWay}"/>
                    </Grid>
                </Border>
            </Grid>
        </Grid>
        
        <!-- Back button and page title -->
        <Grid Grid.Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="BackButton" Margin="39,59,39,0" Command="{Binding NavigationHelper.GoBackCommand, ElementName=PageRoot}"
                        Style="{StaticResource NavigationBackButtonNormalStyle}"
                        VerticalAlignment="Top"
                        AutomationProperties.Name="Back"
                        AutomationProperties.AutomationId="BackButton"
                        AutomationProperties.ItemType="Navigation Button"/>
            <TextBlock x:Name="PageTitle" Text="{StaticResource AppName}" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1" 
                        IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,0,30,40"/>
        </Grid>
    </Grid>
    <Page.BottomAppBar>
        <CommandBar>
            <AppBarButton Icon="Add" Label="Choose Files" Command="{Binding ChooseFilesCommand}"/>
            <AppBarButton Icon="Camera" Label="MediaCapture" Command="{Binding ShowMediaCaptureCommand}"/>
            <AppBarButton Icon="Camera" Label="CameraCaptureUI" Command="{Binding ShowCameraCaptureCommand}"/>
        </CommandBar>
    </Page.BottomAppBar>
</Page>
